package com.shequan.activity.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ailk.dazzle.util.data.JSONUtils;
import com.shequan.activity.bean.bo.ActivityMemberBean;
import com.shequan.activity.service.ActivityMemberService;
import com.shequan.common.bean.ResultDataStruct;
import com.shequan.common.bean.ViewTextConstans;
import com.shequan.shequan.bean.bo.SqActive;

/**
 * 
 * <P>
 * Copyright 2012 shequaner.
 * 
 * All Rights Reserved.
 * 
 * @author mazg
 * @version 1.0, 2012-4-12
 * @see com.shequan.activity.controller.ActivityMemberController
 * @since 1.0
 */
@Controller
@RequestMapping("/activityMember")
public class ActivityMemberController {
	private static final Logger log = Logger.getLogger(ActivityMemberController.class);
	private ActivityMemberService activityMemberService;

	/**
	 * @param activityMemberService
	 *            the activityMemberService to set
	 */
	public void setActivityMemberService(ActivityMemberService activityMemberService) {
		this.activityMemberService = activityMemberService;
	}

	@RequestMapping(value = "/postActivyMember")
	public ModelAndView postActivyMember(HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("---in postActivyMember---");

		ResultDataStruct<SqActive> rds = null;
		try {
			Integer shequanId = Integer.parseInt(request.getParameter("shequanId"));
			System.out.println(shequanId);
//			rds = sqActivityService.shequanAcitiveMsg(shequanId);
			if (rds.isBusiSuccess()) {
				request.setAttribute("sqActive", rds.getData());
			}
		} catch (Exception e) {
			if (rds == null) {
				rds = new ResultDataStruct<SqActive>();
			}
			log.error(e);
			rds.setSuccess(false);
			rds.setMessage(ViewTextConstans.UNKNOW_ERROR_MSG);
		}
		return new ModelAndView("/pages/shequan/shequan.jsp");
	}
	/**
	 * 分页查询活动成员类表
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 * @author mazg
	 * @date 2012-4-12 上午9:26:38
	 */
	@RequestMapping(value = "/getActivyMember")
	public ModelAndView getActivyMember(HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("---in getActivyMember---");

		ResultDataStruct<ActivityMemberBean> rds = new ResultDataStruct<ActivityMemberBean>();
		Integer activityId = null;
		String userName = null;
		Integer userGrender = null;
		Integer page = null;
		Integer limit = null;
		try {
			activityId = Integer.parseInt(request.getParameter("activityId"));
			userName = request.getParameter("userName");
			String userGrenderStr = request.getParameter("userGrenderStr");
			userGrender = userGrenderStr == null || "".equals(userGrenderStr) ? null : Integer.parseInt(userGrenderStr);
			page = Integer.parseInt(request.getParameter("page"));
			limit = Integer.parseInt(request.getParameter("limit"));
			ActivityMemberBean memberBean = new ActivityMemberBean();
			memberBean = activityMemberService.queryActivityMemberByPager(activityId,userName,userGrender,page,limit);
			rds.setData(memberBean);
			rds.setBusiSuccess(true);
			rds.setSuccess(true);
		} catch (Exception e) {
			log.error(e);
			rds.setSuccess(false);
			rds.setMessage(ViewTextConstans.UNKNOW_ERROR_MSG);
		}
		String jsonData = JSONUtils.bean2JsonString(rds);
		response.getWriter().print(jsonData);
		return null;
	}
}
